<?php

/**
 * Comments model
 * 
 * @author    Kanat Gailimov, http://gailimov.info
 * @copyright Copyright (c) Kanat Gailimov (http://gailimov.info) 2011
 */

class Application_Model_DbTable_Comments extends Zend_Db_Table_Abstract
{
    /**
     * DB table name
     * 
     * @var string
     */
    protected $_name = 'zf_comments';

    /**
     * Get comments by post's ID
     * 
     * @param  int   $postId ID of post
     * @return array
     */
    public function getByPostId($postId)
    {
        $postId = intval($postId);
        $row = $this->fetchAll('post_id = ' . $postId);
        if (!$row) {
            throw new Exception('Ошибка! Комментарии не выбраны из базы данных!');
        }
        return $row->toArray();
    }

	 /**
     * Add comment
     * 
     * @param  int    $postId  ID of post
     * @param  string $name    Name of commenter
     * @param  string $email   Email of commenter
     * @param  string $url     URL of commenter
     * @param  string $comment Comment
     * @return bool
     */
    public function add($postId, $name, $email, $url, $comment)
    {
        $postId = intval($postId);
        $data = array(
            'post_id' => $postId,
            'name' => $name,
            'email' => $email,
            'url' => $url,
            'blog_comment' => $comment,
        );
        $this->insert($data);
    }
	
}